package com.demo.logistics.stockControl.ui;

import com.demo.logistics.LogisticsMain;
import com.demo.logistics.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class StockView extends Activity {
	
	private AlertDialog errorDialog;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public void onStop(){
		super.onStop();
	}
	
	public void displayErrorMessage(String msg) {
		if(errorDialog==null){
			System.out.println("error message dialog is null, create dialog");
			AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
			dialogBuilder.setTitle(R.string.app_name);
			dialogBuilder.setMessage(msg);
			dialogBuilder.setNeutralButton(R.string.lbl_btn_ok, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});
			dialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
				
				public void onCancel(DialogInterface dialog) {
					dialog.dismiss();
				}
			});
			errorDialog = dialogBuilder.create();
			errorDialog.show();
		}
		else{
			System.out.println("error message dialog is already started");
			System.out.println("set message and show");
			errorDialog.setMessage(msg);
			errorDialog.show();
		}
	}
	
	public void bindLogoEvent(){
		ImageView img = (ImageView)findViewById(R.id.imageView1);
		img.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				startActivity(new Intent(getApplicationContext(), LogisticsMain.class));
			}
		});
	}

}
